import json
import os
from neo4j import GraphDatabase

from model_config import *

# host = 'bolt://localhost:7687'
# user = 'neo4j'
# password = '&YGV8uhb'
# print(host, user, password)
driver = GraphDatabase.driver(NEO4J_HOST, auth=(NEO4J_USER, NEO4J_PWD))


def run_query(query, params={}):
    with driver.session() as session:
        result = session.run(query, params)
        # response = [r.values()[0] for r in result]
        json_list = result.data()  # 非 json 格式
        response = json.dumps(json_list, ensure_ascii=False)
        print("neo4j查询结果-->", response)
        return response

if __name__ == '__main__':
    print(run_query("""
    MATCH (n:Person) RETURN n LIMIT 25
    """))
